package classic150;

/**
 * <h3>leetcode</h3>
 *
 * @author BigFaceCat
 * @date 2023/11/4 16:26
 * @description <p>逆向三指针方法</p>
 */
public class No88_2 {
    public static void main(String[] args) {
        int[] a = {1, 2, 0, 0, 0};
        int m = 2;
        int[] b = {2, 5, 6};
        int n = 3;
        merge(a, m, b, n);
    }

    public static void merge(int[] n1, int m, int[] n2, int n) {
        //指向n1数组（不为0的有效数）最后的数
        int p1 = m - 1;
        //指向n2数组最后的数
        int p2 = n - 1;
        //指向生成数组的最后数
        int p = m + n - 1;

        while (p2 >= 0) {
            if (p1 >= 0 && n2[p2] < n1[p1]) {
                n1[p--] = n1[p1--];
            } else {
                n1[p--] = n2[p2--];
            }
        }

//        for (int i = 0; i < m + n; i++) {
//            System.out.println(n1[i]);
//        }
    }
}